/**
 * 
 */
package com.gs.practice.thread.ch02;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public class ThreadStopTest {

	public static void main(String[] args) {
		PrinterThread printerThread1 
		= new PrinterThread("Hello Printer 1!!!");
		new Thread(printerThread1).start();
		PrinterThread printerThread2 
		= new PrinterThread("Hello Printer 2!!!");
		new Thread(printerThread2).start();
		try {
			Thread.sleep(8000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		printerThread1.setDone(true);
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		printerThread1.setDone(true);
	}
	
	
}

class PrinterThread implements Runnable{
	private volatile boolean done = false;
	
	private final String data ;

	
	
	
	/**
	 * @param data
	 */
	public PrinterThread(String data) {
		this.data = data;
	}

	


	/**
	 * @param done the done to set
	 */
	public void setDone(boolean done) {
		this.done = done;
	}




	/**
	 * @return the data
	 */
	public String getData() {
		return data;
	}




	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		while(!done){
			System.out.println(data);
		}
	}
	
	
}
